// jest.unit.config.js - 单元测试专用配置文件
module.exports = {
  testEnvironment: 'node',
  setupFilesAfterEnv: ['<rootDir>/tests/unit/setup-unit.js'],
  testMatch: ['<rootDir>/tests/unit/**/*.test.js'],
  collectCoverageFrom: [
    'src/**/*.{js}',
    '!src/index.js',
    '!**/node_modules/**'
  ],
  coverageDirectory: 'coverage/unit',
  coverageReporters: ['text', 'lcov', 'html', 'json'],
  coverageThreshold: {
    global: {
      branches: 60,
      functions: 70,
      lines: 70,
      statements: 70
    }
  },
  testTimeout: 10000, // 单元测试用更短的超时时间
  maxWorkers: 4,
  transform: {
    '^.+\\.js$': 'babel-jest'
  },
  transformIgnorePatterns: [
    'node_modules/(?!(node-fetch|mongoose-fuzzy-searching)/)'
  ],
  moduleFileExtensions: ['js', 'json'],
  testPathIgnorePatterns: ['/node_modules/', '/coverage/'],
  bail: false,
  verbose: true,
  clearMocks: true,
  restoreMocks: true,
  
  // 配置测试报告器
  reporters: [
      'default',
      [
          'jest-html-reporter', 
          {
              pageTitle: 'SQTracker API 单元测试报告',
              outputPath: './test-reports/unit-test-report.html',
              includeFailureMsg: true,
              includeSuiteFailure: true,
              includeConsoleLog: true,
              theme: 'lightTheme', // 可选: 'darkTheme' 或 'lightTheme'
              executionTimeWarningThreshold: 5000, // 超过5秒的测试会标记为警告
              dateFormat: 'yyyy-mm-dd HH:MM:ss',
              sort: 'titleAsc', // 按标题排序
              collapseSuitesByDefault: false,
              customScriptPath: './test-config/custom-script.js',
              customStylePath: './test-config/custom-style.css',
              useCssFile: true,
              showCollectCoverageFrom: true,
              
              // 添加自定义页面信息
              boilerplate: `
                  <div style="text-align: center; margin: 20px; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px;">
                      <h2 style="margin: 0; font-size: 2.2em; font-weight: 300;">🧪 SQTracker API 单元测试报告</h2>
                      <p style="margin: 10px 0 0 0; opacity: 0.9;">构建时间: ${new Date().toLocaleString('zh-CN')}</p>
                      <p style="margin: 5px 0 0 0; opacity: 0.9;">测试环境: Node.js | 框架: Jest</p>
                  </div>
              `,
              
              // 自定义测试结果统计信息
              customInfos: [
                  {key: '📋 项目名称', value: 'SQTracker'},
                  {key: '🔧 版本', value: '1.0.0'},
                  {key: '🧪 测试类型', value: '单元测试'},
                  {key: '🌍 环境', value: 'Development'},
                  {key: '⚡ 框架', value: 'Jest + Node.js'},
                  {key: '📊 覆盖率目标', value: '70%+'}
              ]
          }
      ]
  ],
  
  // 单元测试不需要真实的数据库连接
  globals: {
    'process.env': {
      NODE_ENV: 'test'
    }
  }
};